<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="s" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1">
<title>N6_1F储位管理</title>
<%@include file="/WEB-INF/common/css.jsp"%>
<style>
.xtcardshow {
	width: 80%;
	height: 40px;
	color: #fff;
	text-align: center;
	line-height: 40px;
	border-radius: 50px;
}
</style>
<%@include file="/WEB-INF/common/topjs.jsp"%>
</head>
<body class="layui-layout-body">
	<div class="layui-layout layui-layout-admin">

		<%@include file="/WEB-INF/common/jsp/header.jsp"%>

		<!-- 内容主体区域 -->
		<div class="layui-container" style="padding: 15px;">
			<div class="layui-row">
				<div class="layui-col-md4" style="padding: 5px">
					<div class="layui-card">
						<div class="layui-card-header layui-bg-green">用户信息</div>
						<div class="layui-card-body">
							<p>工号: ${sessionScope.user.no }</p>
							<p>用户名: ${sessionScope.user.username }</p>
						</div>
					</div>
					<div class="layui-card" style="display: none">
						<div class="layui-card-header layui-bg-green">操作</div>
						<div class="layui-card-body">
							<p>
								<button class="layui-btn layui-btn-radius">更改信息</button>
								<button class="layui-btn layui-btn-radius layui-btn-normal">更改密码</button>
							</p>
						</div>
					</div>
					<div class="layui-card">
						<div class="layui-card-header"
							style="background: #5FB878; color: #fff">消息面板</div>
						<div class="layui-card-body"></div>
					</div>
				</div>
				<div class="layui-col-md8" style="padding: 5px">
					<div class="layui-card">
						<div class="layui-card-header layui-bg-cyan">In 手动登记</div>
						<div class="layui-card-body">
							<hr>
							<form class="layui-form" action="" lay-filter="form">
								<div class="layui-form-item">
									<label class="layui-form-label">数量</label>
									<div class="layui-input-block">
										<input type="text" name="num" required lay-verify="required"
											lay-filter="num" placeholder="数量" autocomplete="off"
											class="layui-input" id="num" value="0">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">料号</label>
									<div class="layui-input-block">
										<input type="text" name="liaohao" id="liaohao" required
											lay-verify="required" placeholder="料号" autocomplete="off"
											class="layui-input" value="">
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">机种</label>
									<div class="layui-input-block">
										<select name="dataMachineId" id="machine"
											lay-verify="required" lay-filter="machine">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">类型</label>
									<div class="layui-input-block">
										<select name="dataItemId" id="item" lay-verify="required"
											lay-filter="item">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">状态</label>
									<div class="layui-input-block">
										<select name="dataGJEHStateId" id="gjehState"
											lay-verify="required" lay-filter="gjehState">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">暂放状态</label>
									<div class="layui-input-block">
										<select name="dataTempputStateId" id="tempputState"
											lay-verify="required" lay-filter="tempputState">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">钢架编号</label>
									<div class="layui-input-block">
										<select name="gjNo" id="gjNo" lay-verify="required"
											lay-filter="gjNo">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">大储位</label>
									<div class="layui-input-block">
										<select name="daChuwei" id="daChuwei" lay-verify="required"
											lay-filter="daChuwei">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<label class="layui-form-label">小储位</label>
									<div class="layui-input-block">
										<select name="xiaoChuwei" id="xiaoChuwei"
											lay-verify="required" lay-filter="xiaoChuwei">

										</select>
									</div>
								</div>
								<div class="layui-form-item">
									<div class="layui-input-block">
										<button type="button" class="layui-btn" onclick="dengji()">登记</button>
										<button type="reset" class="layui-btn layui-btn-primary">重置</button>
									</div>
								</div>
							</form>
						</div>
					</div>
				</div>
			</div>
		</div>

		<%@include file="/WEB-INF/common/jsp/footer.jsp"%>

	</div>
	<%@include file="/WEB-INF/common/bottomjs.jsp"%>
	<script>
		$(function() {
			initForm();
		})
		
		function dengji(){
			var info = checkInput();
			if( info != "OK"){
				var imgSrc = ["0601.jpg", "11.gif", "14.gif", "16.gif", "21.gif", "4.gif"];
				var i = Math.floor(Math.random() * imgSrc.length);
				var conHtml = "<img src='${base}/assets/image/alertemoj/"+imgSrc[i]+"' /><br>";
				conHtml += "<h3 style='text-align: center;font-size: 23px;margin-top: 27px;color:#d00d0d;font-weight: bold'>" + info + "</h3>";
				layer.open({
					title : "消息提示",
					content : conHtml,
				});
				return false;
			}
			var hqlhHtml = "<img src='${base}/assets/image/img1.gif' /><br>";
			hqlhHtml += "<h3 style='text-align: center;font-size: 23px;margin-top: 27px;color:#149e5e;font-weight: bold'>系统正在努力工作中，请稍后</h3>";
			var hqlhAreat = layer.open({
				title : '消息提示',
				content : hqlhHtml,
				btn:[],
				closeBtn: 0
			});
			$.ajax({
				url:"${base}/api/dataDetails/hm/in.api",
				type: "post",
				data : {
					num : $("#num").val(),
					liaohao: $("#liaohao").val(),
					dataMachine : $("#machine").val(),
					dataItem : $("#item").val(),
					dataGJEHState : $("#gjehState").val(),
					dataTempputState : $("#tempputState").val(),
					gjNo : $("#gjNo").val(),
					daChuwei : $("#daChuwei").val(),
					xiaoChuwei : $("#xiaoChuwei").val(),
				},
				headers: Apicheck.getHeaders(),
				success: function(result){
					layer.close(hqlhAreat);
					if(result.code == 1001){
						$("#num").val("");
						$("#liaohao").val("");
						layer.msg(result.msg, {icon:6});
					}else{
						layer.msg(result.msg, {icon:5,anim:6});
					}
				}
			});
		}
		function initForm() {
			findMachines();
			findItems();
			findGjehStates();
			findTempputStates();

			findGanjia();
			//findDachuwei();
			//findXiaochuwei();
		}
		
		function findMachines() {
			$.ajax({
				url : "${base}/api/dataMachine/list.api",
				type : "post",
				data : {
					page : 1,
					size : 1000
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#machine").html("");
					$("#machine").append("<option value=''></option>");
					var list = result.data.list;
					for (var i = 0; i < list.length; i++) {
						$("#machine").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
				}
			});
		}
		function findItems() {
			$.ajax({
				url : "${base}/api/dataItem/list.api",
				type : "post",
				data : {
					page : 1,
					size : 1000
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#item").html("");
					$("#item").append("<option value=''></option>");
					var list = result.data.list;
					for (var i = 0; i < list.length; i++) {
						$("#item").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
				}
			});
		}
		function findGjehStates() {
			$.ajax({
				url : "${base}/api/dataGJEHState/list.api",
				type : "post",
				data : {
					page : 1,
					size : 1000
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#gjehState").html("");
					$("#gjehState").append("<option value=''></option>");
					var list = result.data.list;
					for (var i = 0; i < list.length; i++) {
						$("#gjehState").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
				}
			});
		}
		function findTempputStates() {
			$.ajax({
				url : "${base}/api/dataTempputState/list.api",
				type : "post",
				data : {
					page : 1,
					size : 1000
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#tempputState").html("");
					$("#tempputState").append("<option value=''></option>");
					var list = result.data.list;
					for (var i = 0; i < list.length; i++) {
						$("#tempputState").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
				}
			});
		}

		function findGanjia() {
			$.ajax({
				url : "${base}/api/gangjia/list.api",
				type : "post",
				data : {
					page : 1,
					size : 1000
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#gjNo").html("");
					$("#gjNo").append("<option value=''></option>");
					var list = result.data.list;
					for (var i = 0; i < list.length; i++) {
						$("#gjNo").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
					layui.form.on("select(gjNo)", function(data) {
						$("#daChuwei").html("");
						$("#xiaoChuwei").html("");
						$("#daChuwei").val("");
						$("#xiaoChuwei").val("");
						findDachuwei();
					});
				}
			});
		}

		function findDachuwei() {
			$.ajax({
				url : "${base}/api/dachuwei/findByGanjias.api",
				type : "post",
				data : {
					ganjiaName : $("#gjNo").val()
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#daChuwei").html("");
					$("#daChuwei").append("<option value=''></option>");
					var list = result.data.dachuweis;
					for (var i = 0; i < list.length; i++) {
						$("#daChuwei").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
					layui.form.on("select(daChuwei)", function(data) {
						$("#xiaoChuwei").html("");
						$("#xiaoChuwei").val("");
						findXiaochuwei();
					});
				}
			});
		}
		function findXiaochuwei() {
			$.ajax({
				url : "${base}/api/xiaochuwei/findByDachuwei.api",
				type : "post",
				data : {
					dachuweiName : $("#daChuwei").val()
				},
				headers: Apicheck.getHeaders(),
				success : function(result) {
					$("#xiaoChuwei").html("");
					$("#xiaoChuwei").append("<option value=''></option>");
					var list = result.data.xiaochuwei;
					for (var i = 0; i < list.length; i++) {
						$("#xiaoChuwei").append(
								"<option value='"+list[i].name+"'>"
										+ list[i].name + "</option>");
					}
					layui.form.render("select", "form");
				}
			});
		}
		function checkInput(){
			if($("#num").val() == "0" || $("#num").val() == ""){
				return "呵呵呵呵，数量都没有还登记啊";
			}
			if($("#liaohao").val() == ""){
				return "料号呢？";
			}
			if($("#machine").val() == ""){
				return "呵呵呵呵，你没有选择机种";
			}
			if($("#item").val() == ""){
				return "类型是不是又忘记选了";
			}
			if($("#gjehState").val() == ""){
				return "状态呢？咋又不选了？";
			}
			if($("#tempputState").val() == ""){
				return "暂放状态，暂放状态，暂放状态？";
			}
			if($("#gjNo").val() == ""){
				return "这个...那个...钢架编号是不是没选则呀？";
			}
			if($("#daChuwei").val() == ""){
				return "额。。。看看是不是大储位有没有选择";
			}
			if($("#gjNo").val() == "D01" && $("#xiaoChuwei").val() == ""){
				return "呵呵呵，钢架编号D01有小储位, 你估计又是没有选择小储位";
			}
			return "OK";
		}
	</script>
</body>
</html>